/*
 * sr_p.h - EnCluster Standard Representation Provate Definitions
 * Clunix, yjlee@clunix.com, 7.25.
 *
 * Copyright (c) 2001-2005 by Clunix Inc. All Rights Reserved.
 */

#ifndef SR_P_H
#define SR_P_H

#include "sr_type.h"

#define SR_NAME_MAX    256	/* maximum length + 1 */

typedef struct {
	LNI_type_t	type;
	char		*name;
} LNI_t;

typedef enum {
	LNP_TYPE_ABS,
	LNP_TYPE_REL
} LNPath_type_t;

typedef struct {
	LNPath_type_t	type;
	ECMBOOL	is_ref;
	int	n_LNI;
	LNI_t	LNIs[0];
} LNPath_t;

typedef struct {
	char	*instr;
	int	instr_len;
	int	instr_ptr;
} asr_input_t;

/* SR data structure */

const sr_type_t *srt_get_info(srt_t srt);
ecm_size_t srt_get_namelen(srt_t srt);
sr_printer_t srt_get_printer(srt_t srt);
sr_scanner_t srt_get_scanner(srt_t srt);

ECM_INLINE ecm_size_t sizeof_encode_str(char *str);

int srt_enum_print(srt_t srt, char *buf, ecm_size_t *pbuflen, sr_val_t srv);
ECMBOOL srt_enum_scan(srt_t srt, char *asrv, sr_val_t *psrv);
int srt_bitwise_print(srt_t srt, char *buf, ecm_size_t *pbuflen, sr_val_t srv);
ECMBOOL srt_bitwise_scan(srt_t srt, char *asrv, sr_val_t *psrv);

ECMBOOL srt_dir_scan(srt_t srt, char *asrv, sr_val_t *psrv);
int srt_ref_print(srt_t srt, char *buf, ecm_size_t *pbuflen, sr_val_t srv);
ECMBOOL srt_ref_scan(srt_t srt, char *asrv, sr_val_t *psrv);

ecm_size_t sizeof_encode_ref(ecm_ptr_t ptr, int apply_opt);

void sr_free_ref(ecm_ptr_t ptr);

LNPath_t *parse_LNP(const char *LNP);
void free_LNP(LNPath_t *LNPath);
char *get_last_LNI(const char *LNPstr);

typedef void *yyscan_t;

int srpparse(yyscan_t scanner, sr_t **);
asr_input_t *srpget_extra(yyscan_t scanner);
void srplex_init(yyscan_t *);
void srplex_destroy(yyscan_t);
void srpset_extra(void *, yyscan_t);
void srpset_debug(int, yyscan_t);

static ECM_INLINE char *
find_escstr_chr(const char *buf, char sep, ecm_size_t *plen)
{
	ecm_size_t	len = 0;

	while (*buf) {
		if (*buf == '\\') {
			if (buf[1] == '\0')
				return NULL;
			len++;
			buf += 2;
			continue;
		}
		else if (*buf == sep) {
			if (plen) *plen = len;
			return (char *)buf;
		}
		len++;
		buf++;
	}
	return NULL;
}

#endif				/* SR_P_H */
